import { App as AntdApp } from "antd";
import { Helmet } from "react-helmet-async";
import { ConfigProvider } from "@/contexts/ConfigContext";
import { useConfig } from "@/contexts/ConfigContext";

import Logo from "@/assets/images/logo.png";
import Router from "@/router/index";
import AntdConfig from "@/theme/antd";
import { APP_CONFIG } from "@/config/app";

import { MotionLazy } from "./components/animate/motion-lazy";
import Toast from "./components/toast";

function App() {
	return (
		<ConfigProvider>
			<App.Content />
		</ConfigProvider>
	);
}

// 主要内容组件
App.Content = function AppContent() {
	const { config, loading } = useConfig();

	return (
		<AntdConfig>
			<AntdApp>
				<MotionLazy>
					<Helmet>
						<title>{config?.name || "加载中..."}</title>
						{config?.website_logo && (
							<link rel="icon" href={config.website_logo} />
						)}
					</Helmet>
					<Toast />

					<Router />
				</MotionLazy>
			</AntdApp>
		</AntdConfig>
	);
};

export default App;
